package cn.jsj.dispose;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.object.FrontLawyer;
import cn.jsj.object.FrontPracLawyer;
import cn.jsj.pojo.TblPracticeLawyer;
import cn.jsj.utils.ProduceJsonData;
import cn.jsj.utils.SysLogger;

/**
 * 查询实习律师信息处理类
 * @author LI
 *
 */
public class SearchPracLawyerInfo extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("进入查shixi律师信息处理类");
		//获取参数：1.实习律师姓名 2.指导老师姓名
		String pracLawyerName=request.getParameter("pracLawName").trim();
		pracLawyerName = new String(pracLawyerName.getBytes("ISO-8859-1"), "utf-8");
		String pracGuideTeacher=request.getParameter("pracGuideTeacher").trim();
		pracGuideTeacher = new String(pracGuideTeacher.getBytes("ISO-8859-1"), "utf-8");
		
		//获得限定条件 从第几条开始，一页显示几条
		int startNumb=Integer.parseInt(request.getParameter("start"));
		int totalNumb=Integer.parseInt(request.getParameter("limit"));
		
		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("获得的参数为--->"+pracLawyerName+pracGuideTeacher+startNumb+totalNumb);
		
		//新建实习律师操作对象
		cn.jsj.dao.TblPracticeLawyerDAO tpld=new cn.jsj.dao.TblPracticeLawyerDAO();
		//获得符合条件的实习律师信息条数
		int pracLawyerInfoNumb=tpld.getSearchPracLawyerInfoNumb(pracLawyerName, pracGuideTeacher);
		
		//调试信息
		SysLogger.PrintInfo(pracLawyerInfoNumb);
		
		
		//根据条件查询律师信息
		java.util.List<TblPracticeLawyer> pracLawyerList=new java.util.LinkedList<TblPracticeLawyer>();
		pracLawyerList=tpld.getSearchPracLawyerInfo(pracLawyerName, pracGuideTeacher, startNumb, totalNumb);
		
		
		//调试信息
		SysLogger.PrintInfo(pracLawyerList.size());
		
		//前台实习律师信息对象队列
		java.util.List<FrontPracLawyer> frontLawyerInfo=new java.util.LinkedList<FrontPracLawyer>();
		//改造成前台需要的律师信息对象
		cn.jsj.object.rebuild.PracLawyerInfoRebuild plir=new cn.jsj.object.rebuild.PracLawyerInfoRebuild();
		for(int i=0;i<pracLawyerList.size();i++){
			cn.jsj.object.FrontPracLawyer fpl=plir.rebuildPracLawyer(pracLawyerList.get(i));
			frontLawyerInfo.add(fpl);
		}
			
			//改造成JSON型数据
			ProduceJsonData pjd=new ProduceJsonData();
		String resultData=	pjd.jsonFromList(frontLawyerInfo,pracLawyerInfoNumb);
			
		//调试信息
		SysLogger.PrintInfo(resultData);
		//输出到客户端
		java.io.PrintWriter pw=response.getWriter();
		pw.println(resultData);
		pw.flush();
		
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request,response);
	}

}
